package com.example.demo.controller;

import com.example.demo.aspect.NoRepeatSubmit;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class UserController {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    private static final String _RedisKey = "SpringBoot2";

    @NoRepeatSubmit(lockTime = 10)
    @RequestMapping("/hi")
    public String sayHi() {
        // redis 存值
        stringRedisTemplate.opsForValue().set(_RedisKey, "Spring Boot");
        // redis 中取值
        String rdValue = stringRedisTemplate.opsForValue().get(_RedisKey);
        return "Hi, " + rdValue;
    }
}
